
const util = require('../../utils/util.js');
Page({
  data: {
    showpopup: false,
    list2: [
      {
        name: '家政员',
        id: 0,
        ch: true
      },
      {
        name: '月嫂',
        id: 1,
        ch: false
      },
      {
        name: '育儿嫂',
        id: 2,
        ch: false
      },
      {
        name: '保洁',
        id: 3,
        ch: false
      },
      {
        name: '护工',
        id: 4,
        ch: false
      },
      {
        name: '餐饮服务',
        id: 5,
        ch: false
      },
      {
        name: '酒店服务',
        id: 6,
        ch: false
      },
      {
        name: '销售',
        id: 7,
        ch: false
      },
      {
        name: '做生意',
        id: 8,
        ch: false
      },
      {
        name: '其他',
        id: 9,
        ch: false
      },

    ],
    selectIndex2: '',
    content: '',
    begDate: '',
    endDate: '',
    position: '',

    workExperiences: [

    ]
    // date: '',
    // show: true,
  },
  clickItem2(e) {
    const data = e.currentTarget.dataset;
    this.setData({
      selectIndex2: data.index,
      position: data.item.name
    })
  },
  doDel(e) {
    const data = e.currentTarget.dataset;
    this.data.workExperiences.splice(data.index, 1)
    this.setData({
      workExperiences: this.data.workExperiences
    })
  },
  doItem(e) {
    const data = e.currentTarget.dataset;
    this.setData({
      content: data.item.content,
      begDate: data.item.begDate,
      endDate: data.item.endDate,
      position: data.item.position,
      selectIndex2: data.item.positionId,
    })
  },
  bindDateChange1(e) {
    this.setData({
      begDate: e.detail.value
    })
  },
  bindDateChange2(e) {
    this.setData({
      endDate: e.detail.value
    })
  },
  doAdd() {
    this.setData({
      selectIndex2: '',
      content: '',
      begDate: '',
      endDate: '',
      position: '',
      showpopup: true
    })
  },
  doCancel() {
    this.setData({
      showpopup: false
    })
  },
  nbuy2() {
    const data = this.data;
    if (data.position === '' || data.position == null) {
      wx.showModal({
        title: '温馨提示',
        content: '工作不能为空！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    if (data.begDate === '' || data.endDate == null) {
      wx.showModal({
        title: '温馨提示',
        content: '开始日期和结束日期不能为空！',
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })
      return
    }
    this.data.workExperiences.push({
      content: data.content,
      begDate: data.begDate,
      endDate: data.endDate,
      position: data.position,
      positionId: data.selectIndex2
    })
    this.setData({
      showpopup: false,
      workExperiences: this.data.workExperiences
    })
  },
  doNext() {
    let data = this.data;
    try {
      let storageData = wx.getStorageSync('bmhetong');
      storageData.workExperiences = data.workExperiences;
      util.https('resume/resumeAdd', storageData, (res) => {
        console.log(res)
        wx.navigateTo({ url: '/page5/bmhetongsuccess/index' })
      }, (res) => {
        console.log(res)
        wx.showModal({
          title: '温馨提示',
          content: res.errorMsg,
          confirmColor: '#F08302',
          showCancel: false,
          success(res) {
          }
        })
      }, null, true)
    } catch (e) { }

  },
  doBack() {
    wx.navigateBack({
      delta: 1
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
  
})